package com.sjq.common.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.sjq.common.dao.GenericDao;
import com.sjq.common.dao.ItemDao;
import com.sjq.common.entity.Item;
@Repository
public class ItemDaoImpl extends GenericDao<Item> implements ItemDao {
	
	private String getSql(){
		String sql=" select *  "+
				  " from t_sys_dmx ";
		return sql;

	}

	@Override
	public List<Item> queryAll() {
		String sql=getSql()+" where bgbs<>'3' ";
		
		return this.getJdbcTemplate().query(sql, new BeanPropertyRowMapper(Item.class));
	}
	
	
	 @Override
	 public List<Map<String, String>> findItemByListAll(String zdlbdm){
		StringBuilder paramSql = new StringBuilder();
		List params = new ArrayList();
		
		paramSql.append(" and zdlbdm=? ");
		params.add(zdlbdm.trim());
		String sql="select zdlbdm,zdlbmc,zddm,zdmc from T_SYS_DMX where  BGBS <>3  "+ paramSql.toString() +" order by zddm asc";
		List<Map<String, String>> list=new ArrayList<Map<String, String>>();
		try {
			list = this.getListBySql(sql.toString(),params.toArray());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}


	@Override
	public List<Item> query(Item Item) {
		String wheres=" where 1=1 ";
		if(Item.getZdlbdm()!=null&&!"".equals(Item.getZdlbdm())&&!"null".equals(Item.getZdlbdm())){
			wheres+=" and fzddm ='"+Item.getFzddm()+"' ";
		}
		
		String sql=getSql()+wheres+" and bgbs<>'3' ";
		
		return this.getJdbcTemplate().query(sql, new BeanPropertyRowMapper(Item.class));
	}

	

}
